
package de.fhhof.brst.event;

import java.io.Serializable;
import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import de.fhhof.brst.dao.EventDAO;
import de.fhhof.brst.dao.HibernateEventDAO;
import de.fhhof.brst.data.Event;
import de.fhhof.brst.session.SessionBean;
@ManagedBean
@ViewScoped
public class EditEvent implements Serializable {
  /**
   * 
   */
  private static final long serialVersionUID =  1083930177230325863L;

  private de.fhhof.brst.data.Event event;

  private de.fhhof.brst.dao.EventDAO eventDAO =  HibernateEventDAO.getHibernateEventDAO();

  @ManagedProperty(value = "#{sessionBean}")
  private de.fhhof.brst.session.SessionBean sessionBean;

  public EditEvent() {

  }

  @PostConstruct
  public void init() {
		event = sessionBean.getSelectedEvent();
  }

  public String submit() {
		FacesMessage message = new FacesMessage("Event gespeichert!");

		eventDAO.editEvent(event);

		FacesContext.getCurrentInstance().addMessage(null, message);
		
		return "/events_frame.xhtml?faces-redirect=true";
  }

  public de.fhhof.brst.data.Event getEvent() {
		return event;
  }

  public void setEvent(de.fhhof.brst.data.Event event) {
		this.event = event;
  }

  public void setSessionBean(de.fhhof.brst.session.SessionBean sessionBean) {
		this.sessionBean = sessionBean;
  }

  public de.fhhof.brst.session.SessionBean getSessionBean() {
		return sessionBean;
  }

}
